import logging
import time

import pytest

from resource.pom.contacts import Contacts
from resource.pom.keyboard import Keyboard

@pytest.fixture(autouse=True)
def preset_contactor(device):
    logging.info('方法前置----预置联系人')
    Contacts.create_contactor(device)
    yield
    logging.info('方法后置----删除联系人')
    Contacts.delete_contactor(device)


class Test:
    app = Contacts
    keyboard = Keyboard

    @pytest.mark.parametrize('setup_teardown', [app.bundle_name], indirect=True)
    def test(self, setup_teardown, device):
        logging.info('步骤1.进入桌面，点击联系人搜素框输入搜索内容（若无"联系人"需要先新增联系人）')
        device.start_ability(self.app.bundle_name, self.app.ability_name)
        device.click(*self.app.menu_contacts)
        device.refresh_layout()

        text_input = device.get_element_by_type('TextInput')
        device.click_element(text_input)
        device.refresh_layout()
        text_input = device.get_element_by_type('TextInput')
        device.click_element(text_input)
        logging.info('预期结果1.点击搜索框可正常唤醒键盘，只显示与输入的内容相对应的联系人')
        device.refresh_layout()
        device.assert_soft_keyboard_on()
        device.click(*self.keyboard.key_a)
        device.refresh_layout()
        device.assert_text_exist(self.app.test_number)
